Electrical Engineering (EE) Exam  >  Electrical Engineering (EE) Questions  >  How is an array initialized in C language?a)i... Start Learning for Free
How is an array initialized in C language?
  • a)
    int a[3] = {1, 2, 3};
  • b)
    int a = {1, 2, 3};
  • c)
    int a[] = new int[3]
  • d)
    int a(3) = [1, 2, 3];
Correct answer is option 'A'. Can you explain this answer?
Most Upvoted Answer
How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int...
In C language, an array can be initialized by providing a comma-separated list of values enclosed in braces ({}) after the declaration.
In option A, the array a is declared as an integer array of size 3 using the syntax int a[3]. The values 1, 2, and 3 are then provided within the braces to initialize the elements of the array.
Option B, int a = {1, 2, 3}, is incorrect because it tries to initialize a single integer variable a with multiple values, which is not valid. Array initialization requires the use of square brackets [] to declare an array.
Option C, int a[] = new int[3], is not valid C syntax. The new keyword is not used in C language for array initialization.
Option D, int a(3) = [1, 2, 3], is also incorrect syntax. The parentheses () and the use of square brackets [] are used incorrectly. Proper array initialization requires the use of square brackets [] and braces {}.
Therefore, the correct answer is A) int a[3] = {1, 2, 3}; as it demonstrates the correct syntax for initializing an array in C.
Free Test
Community Answer
How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int...
Initializing an Array in C Language

In the C programming language, an array is a collection of elements of the same data type. It is a fixed-size sequential collection of elements, and each element is accessed by its index. Initializing an array means assigning initial values to its elements during its declaration.

Correct Option: A
The correct way to initialize an array in C language is:

a) int a[3] = {1, 2, 3};

Let's break down the initialization process in the given option:

1. int a[3]: This part declares an integer array named 'a' with a size of 3 elements. The square brackets '[]' indicate the size of the array.

2. = {1, 2, 3}: This part initializes the array elements with the values 1, 2, and 3. The curly braces '{ }' contain the values to be assigned to the array elements. Each value is separated by a comma.

Explanation of Other Incorrect Options:

b) int a = {1, 2, 3};
- This option is incorrect because it tries to initialize a single integer variable 'a' with multiple values using curly braces. It is not valid syntax for initializing an array.

c) int a[] = new int[3]
- This option is not valid in the C language. The syntax 'new int[3]' is used in languages like C++ or Java to dynamically allocate memory for an array. In C, arrays are statically allocated, so we don't use 'new' keyword for initialization.

d) int a(3) = [1, 2, 3];
- This option is also incorrect. The parentheses '(3)' are not valid syntax for array initialization in C. Moreover, the square brackets '[ ]' are not used while initializing an array.

Conclusion:

In C language, arrays can be initialized during their declaration using curly braces '{ }'. The correct syntax for initializing an array is int a[3] = {1, 2, 3}, where 'a' is the array name, '3' is the size of the array, and the values inside the curly braces are the initial values assigned to the array elements.
Explore Courses for Electrical Engineering (EE) exam
Question Description
How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int a = {1, 2, 3};c)int a[] = new int[3]d)int a(3) = [1, 2, 3];Correct answer is option 'A'. Can you explain this answer? for Electrical Engineering (EE) 2025 is part of Electrical Engineering (EE) preparation. The Question and answers have been prepared according to the Electrical Engineering (EE) exam syllabus. Information about How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int a = {1, 2, 3};c)int a[] = new int[3]d)int a(3) = [1, 2, 3];Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for Electrical Engineering (EE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int a = {1, 2, 3};c)int a[] = new int[3]d)int a(3) = [1, 2, 3];Correct answer is option 'A'. Can you explain this answer?.
Solutions for How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int a = {1, 2, 3};c)int a[] = new int[3]d)int a(3) = [1, 2, 3];Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for Electrical Engineering (EE). Download more important topics, notes, lectures and mock test series for Electrical Engineering (EE) Exam by signing up for free.
Here you can find the meaning of How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int a = {1, 2, 3};c)int a[] = new int[3]d)int a(3) = [1, 2, 3];Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int a = {1, 2, 3};c)int a[] = new int[3]d)int a(3) = [1, 2, 3];Correct answer is option 'A'. Can you explain this answer?, a detailed solution for How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int a = {1, 2, 3};c)int a[] = new int[3]d)int a(3) = [1, 2, 3];Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int a = {1, 2, 3};c)int a[] = new int[3]d)int a(3) = [1, 2, 3];Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice How is an array initialized in C language?a)int a[3] = {1, 2, 3};b)int a = {1, 2, 3};c)int a[] = new int[3]d)int a(3) = [1, 2, 3];Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Electrical Engineering (EE) tests.
Explore Courses for Electrical Engineering (EE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev